package cn.edu.lcvc.ebuy_2023rj2.model.common;

/**
 * 响应客户端的实体类
 */
public class ResponseData<T> {
    private Integer code;//表示htttp状态码，例如404，500，405，200（表示正常访问）
    private Boolean success;//业务操作是否成功，true表示成功，false表示失败
    private String msg;//返回的提示信息
    private T data;//返回的数据， 如果没有返回数据，则显示空字符串

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public ResponseData(Integer code, Boolean success, String msg, T data) {
        this.code = code;
        this.success = success;
        this.msg = msg;
        if (data!=null){
            this.data = data;
        }else{
            this.data= (T)new String();
        }

    }

    /**
     * 成功的业务
     * @param data 要返回的数据
     * @param <V>
     * @return
     */
    public static<V> ResponseData success(V data){
        return new ResponseData(200,true,"操作成功",data);
    }

    public static<V> ResponseData success(){
        return new ResponseData(200,true,"操作成功",null);
    }

    /**
     * 业务失败调用
     * @param msg  要返回的错误信息
     * @param <V>
     * @return
     */
    public static<V> ResponseData error(String msg){
        return new ResponseData(200,false,msg,null);
    }

    public static<V> ResponseData error(Integer code,String msg){
        return new ResponseData(401,false,msg,null);
    }
}
